/**
 *******************************************************************************
 * @FileName  : kv_port.c
 * @Author    : GaoQiu
 * @CreateDate: 2021-4-27
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#include "kv.h"
#include "kv_port.h"
#include "kv_type.h"
#include "platform/platform.h"
#include "bsp/bsp.h"

#include "utils/track.h"

extern kv_t kv;

int kv_port_flash_init(void)
{
	return KV_OK;
}

int kv_port_flash_write(uint32_t addr, uint8_t *pdata, uint32_t len)
{
	HalFlashWrite(CONFIG_KV_FLASH_START_ADDR + addr, pdata, len);
	return KV_OK;
}

int kv_port_flash_read(uint32_t addr, uint8_t *pdata, uint32_t len)
{
	HalFlashRead(CONFIG_KV_FLASH_START_ADDR + addr, pdata, len);
	return KV_OK;
}

int kv_port_flash_erase(uint32_t addr, uint32_t blockNum)
{
	uint32_t sectorNum = blockNum * CONFIG_KV_BLOCK_SIZE/CONFIG_KV_FLASH_SECTOR_SIZE;
	addr += CONFIG_KV_FLASH_START_ADDR;
	for(int i=0; i<sectorNum; i++, addr += CONFIG_KV_FLASH_SECTOR_SIZE)
	{
		HalFlashEraseSector(addr);
	}
	return KV_OK;
}


